open cic
open csr
open ea
open eap

// ------------------------------------------------------------
//  CA - Connector Architecture
// ------------------------------------------------------------

one sig CA_RPC extends CA {}
fact CA_RPC {
	EmployedCA[CA_RPC] => {
		//AvailableRoles[CSR_Client + CSR_Server]

		//RoleCardinalitySingle[CSR_Server]
		//RoleCardinalityMultiple[CSR_Client]

		//SupportedGlobalFeatures[FT_Security]

		-- define implementation (EA, associated port, feature dlegation) of all supported roles
		all rm: CIC.rmap[univ] | {
			-- client unit
			rm.role = CSR_Client => {
				AllowedEAs[rm, EA_ClientStub]
				// Vynechat: AvailablePorts[rm, EAPLP_CallIn + EAPR_MW]
				AssociateRoleWithPort[rm, EAPLP_CallIn]
			}
			-- server unit
			rm.role = CSR_Server => {
				AllowedEAs[rm, EA_ServerSkeleton]
				// Vynechat: AvailablePorts[rm, EAPLR_CallOut + EAPR_MW]
				AssociateRoleWithPort[rm, EAPLR_CallOut]

				//DelegateGlobalFeaturesToRole[rm, FT_Security]
			}
		}

		-- port EAPR_MW of unit implenting CSR_Client is bound to port EAPR_MW of unit
		-- implemnting CSR_Server
		RemoteBinding[CSR_Client, EAPR_MW, CSR_Server, EAPR_MW]
	}
}

//one sig CA_UnixSockets extends CA {}

pred EmployedCA[c: CA] {
	CIC.ca = c
}

pred AllowedEAs[rm: DRURMapping, allowedEAs: set EA] {
	rm.unit.ea in allowedEAs
}

pred AvailablePorts[rm: DRURMapping, availablePorts: set EAP] {
	rm.unit.portSignatures.univ = availablePorts
}

pred AssociateRoleWithPort[rm: DRURMapping, port: EAPL] {
	rm.unit.portSignatures[port] = rm.signature
}

pred RemoteBinding[r1: CSR, p1: EAPR, r2: CSR, p2: EAPR] {
	-- there is one signature, shared by both ports
	one signature: S | all rm: CIC.rmap[univ] | {
		rm.role = r1 => rm.unit.portSignatures[p1] = signature
		rm.role = r2 => rm.unit.portSignatures[p2] = signature
	}
}
